public class MyBinaryTree {
    static class BinaryTree {
        public BinaryTree left;
        public int val;
        public BinaryTree right;
    }
    public boolean isSameTree(BinaryTree tree1,BinaryTree tree2){
        if (tree1 == null && tree2== null) {
            return true;//两节点同时为空返回true
        }
        if ((tree1 == null && tree2 != null) || (tree1 != null && tree2 == null)) {
            return false;//两节点不相同返回false
        }
        if (tree1.val != tree2.val) {
            return false;//两节点值不相同返回false
        }
        Boolean leftTree = isSameTree(tree1.left,tree2.left);
        Boolean rightTree = isSameTree(tree1.right, tree2.right);

        return leftTree && rightTree;//左右子树都相同返回true
    }


    public boolean isSubTree(BinaryTree root,BinaryTree subRoot) {
        if (root == null || subRoot == null) {
            return false;
        }
        if (isSameTree(root,subRoot)) {
            return true;
        }
        if (isSubTree(root.left,subRoot)) {
            return true;
        }
        if (isSubTree(root.right,subRoot)) {
            return true;
        }

        return  false;
    }
}
